package cn.est.controller;
import cn.est.pojo.BrandClassifyRelation;
import cn.est.constants.Constants;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.service.BrandClassifyRelationService;
import cn.est.utils.EmptyUtils;
import cn.est.utils.ResultUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/client/brandClassifyRelation")
public class BrandClassifyRelationController {

    @Resource
    private BrandClassifyRelationService brandClassifyRelationService;

    @RequestMapping("/search")
    @ResponseBody
    public Page<BrandClassifyRelation> searchBrandClassifyRelation(@RequestParam Map<String,Object> param) {
        Page<BrandClassifyRelation> brandClassifyRelationPage = null;
        try {
            Integer pageNo= EmptyUtils.isEmpty(param.get("pageNo"))? Page.DEFAULT_PAGE_NO:Integer.parseInt((String) param.get("pageNo"));
            Integer pageSize= EmptyUtils.isEmpty(param.get("pageSize"))? Page.DEFAULT_PAGE_SIZE:Integer.parseInt((String) param.get("pageSize"));
            brandClassifyRelationPage  = brandClassifyRelationService.queryBrandClassifyRelationPageByMap(param, pageNo, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return brandClassifyRelationPage;
    }

    @RequestMapping("/saveOrUpdateBrandClassifyRelation")
    @ResponseBody
    public Result saveOrUpdateBrandClassifyRelation(BrandClassifyRelation brandClassifyRelation){
        Integer flag=0;
        try {
            if(EmptyUtils.isEmpty(brandClassifyRelation.getId())){
                flag=brandClassifyRelationService.qdtxAddBrandClassifyRelation(brandClassifyRelation);
            }else{
                flag=brandClassifyRelationService.qdtxModifyBrandClassifyRelation(brandClassifyRelation);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag>=1?ResultUtils.returnSuccess():ResultUtils.returnFail();
    }

    @RequestMapping("/getBrandClassifyRelationById")
    @ResponseBody
    public Result getBrandClassifyRelationById(Long id){
        Result result= ResultUtils.returnSuccess();
        BrandClassifyRelation brandClassifyRelation=null;
        try {
            brandClassifyRelation=brandClassifyRelationService.getBrandClassifyRelationById(id);
            result.setData(brandClassifyRelation);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/batchRemoveBrandClassifyRelation")
    @ResponseBody
    public Result batchRemoveBrandClassifyRelation(String ids){
        Integer flag=0;
        try {
            flag=brandClassifyRelationService.qdtxBatchDeleteBrandClassifyRelation(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }

    @RequestMapping("/removeBrandClassifyRelationById")
    @ResponseBody
    public Result removeBrandClassifyRelationById(Long id){
        Integer flag=0;
        try {
            flag=brandClassifyRelationService.qdtxDeleteBrandClassifyRelationById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }
}
